<?php
include "../connect/connect_dsccmis.php";
include "../common/commonFns.php";

// get last update for select data set to set lat lng
$sql = "select max(upddte) as upddte from gis_event_lastupdate";
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs);
$upddte=$row["upddte"];
// select dataset
$sql = "SELECT evnid,tarx,tary FROM gis_event where (lat is null or lat = '') and (tarx is not null) and (tarx <> '') and (tary is not null) and (tary <> '') and (upddte >= '$upddte')  order by evnid desc";
//echo "<br>$sql";
mysql_query("set names utf8");
$result = mysql_query($sql);
if (!$result)
{
	echo "no results ";
}else{
	$i=0;
	while($row = mysql_fetch_array($result)){
		$evnid=$row["evnid"];
		$tarx=$row["tarx"];
		$tary=$row["tary"];
		$arrlatlng=LatLonPointUTMtoLL($tary, $tarx, $j=47);
		$sql_update="update gis_event set lat=".$arrlatlng["lat"].",lng=".$arrlatlng["lng"]." where evnid=".$evnid;
		//echo "<br>$sql_update";
		mysql_query($sql_update);
		$i++;
	}
	echo "<br>update lat lng in gis_event $i rows";
	$sql = "select max(upddte) as new_upddte from gis_event";
	$rs=mysql_query($sql);
	$row=mysql_fetch_array($rs);
	$new_upddte=$row["new_upddte"];
	//update  last update
	$sql = "update gis_event_lastupdate set upddte = '".$new_upddte."'";
	//echo "<br>".$sql;
	$rs=mysql_query($sql);
	echo "last update $new_upddte";
}
//mysql_close($c);
?>
